<!DOCTYPE html>
<html lang="zh">
<head>
    <include file="index/index_style" title="管理后台"/>
</head>
<body class="navbar-fixed">
<!-- header -->
<include file="index/header"/>
<!-- / header -->

<!-- menu -->
<include file="index/menu" class="active"/>
<!-- / menu -->

<section id="content">
    <section class="main padder">
        <div class="clearfix">
            <h4><i class="icon-tags"></i>标签</h4>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <!-- .breadcrumb -->
                <ul class="breadcrumb">
                    <li><a href="#"><i class="icon-home"></i>主页</a></li>
                    <li><a href="#"><i class="icon-file-text"></i>新闻</a></li>
                    <li class="active">标签</li>
                </ul>
                <!-- / .breadcrumb -->
            </div>
            <div class="col-lg-12">
                <section class="panel">
                    <volist name="tags" id="tag">
                        <a class="m-t-small btn btn-default" href="javascript:void(0);">{$tag.name}&nbsp;<i class="icon icon-trash text-info delete-tag" data-tid="{$tag.tid}"></i></a>
                        &nbsp;
                    </volist>
                    <a class="m-t-small btn btn-primary" data-toggle="modal" href="#add-tag"><i class="icon-plus"></i>添加</a>
                </section>
            </div>
        </div>
    </section>
</section>

<!-- .modal -->
<div id="add-tag" class="modal fade">
    <div class="modal-dialog pos-abt" style="margin-top:-235px; top:50%">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i
                        class="icon-remove"></i></button>
                <h4 class="modal-title" id="">添加标签</h4>
            </div>
            <div class="modal-body">
                <div class="block">
                    <label class="control-label">名称</label>
                    <input id="tagname" name="name" type="text" class="form-control" placeholder="名称">
                </div>

                <!-- 提示消息 -->
                <div class="alert alert-warning message-alert-box" style="display: none">
                    <i class="icon-bell-alt"></i><strong><span class="message-alert"></span></strong>
                </div>

                <div class="alert alert-success message-success-box" style="display: none">
                    <i class="icon-ok-sign icon-large"></i><strong><span class="message-success"></span></strong>
                </div>


            </div>
            <div class="modal-footer">
                <button id="submit" type="button" class="btn btn-small btn-primary">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div>
</div>
<!-- / .modal -->


<script src="__PUBLIC__/js/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="__PUBLIC__/js/bootstrap.js"></script>
<!-- app -->
<script src="__PUBLIC__/js/app.js"></script>
<script src="__PUBLIC__/js/app.plugin.js"></script>
<script src="__PUBLIC__/js/app.data.js"></script>

<!-- Sparkline Chart -->
<script src="__PUBLIC__/js/charts/sparkline/jquery.sparkline.min.js"></script>
<!-- Easy Pie Chart -->
<script src="__PUBLIC__/js/charts/easypiechart/jquery.easy-pie-chart.js"></script>
<script src="__PUBLIC__/js/ie/excanvas.js"></script>

<!-- page script -->
<script>
    $("#submit").click(function () {
        var name = $.trim($('#tagname').val());
        if(name == ""){
            $(".message-alert").text('标签名不能为空');
            $(".message-alert-box").fadeIn();
            $(".message-alert-box").fadeOut(3000);
            return false;
        }

        $.ajax({
            'type': 'post',
            'data': {'name': name},
            'url': '/Admin/Tag/add',
            'dataType': 'json',
            success: function (data) {
                if(data.code == 2){
                    $(".message-alert-box").hide();
                    $(".message-success").text(data.message);
                    $(".message-success-box").fadeIn();
                    setTimeout(function(){
                        window.location.reload();
                    },800);
                }else {
                    $(".message-alert").text(data.message);
                    $(".message-alert-box").fadeIn();
                    $(".message-alert-box").fadeOut(2500);
                }
            },
            error: function (e) {
                $(".message-alert").text('服务器繁忙');
                $(".message-alert-box").fadeIn();
                $(".message-alert-box").fadeOut(3000);
            }
        });
    });

    $(".delete-tag").click(function () {
        var tid = $(this).attr("data-tid");
        $.ajax({
            'type': 'post',
            'data': {'tid': tid},
            'url': '/Admin/Tag/delete',
            'dataType': 'json',
            success: function (data) {
                if(data.code == 1){
                    window.location.href="/Admin/Tag";
                }
            }
        });
    });
</script>
</body>
</html>